package com.project.web;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class CodeServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name=request.getParameter("cname");
		
		
	
		if("".equals(name) || name == null) {
			name = "1.jpg";
		}
		File file = new File("C:/upload",name);
		
		if(file.exists()) {
			
			InputStream in = new FileInputStream(file);
			
			OutputStream out = response.getOutputStream();
			
			byte[] buffer = new byte[1024];
			
			int len = -1;
			while((len = in.read(buffer)) != -1) {
				out.write(buffer,0,len);
			}
			
			out.flush();
			in.close();
			out.close();
		} else {
			response.sendError(404);
		}
		
	}

	

}
